home *** CD-ROM | disk | FTP | other *** search
/ Visual Cafe 3 / Visual Cafe 3.ISO / Vcafe / Sample.bin / Mediator.java < prev    next >
Text File  |  1997-06-01  |  2KB  |  89 lines

  1. /*
  2.  * Title: Conversing Applets
  3.  * Type: Applet
  4.  * Source: Mediator.java
  5.  * Application Description:
  6.  * The Conversing Applets project provides a simple and effective way
  7.  * to allow applets to communicate within the same "environment", i.e.
  8.  * within the same browser page.
  9.  *
  10.  * This is done using a Mediator class as the background manager and
  11.  * other visible classes which display results. The Mediator class uses
  12.  * static variables to keep track of all the events taking place in
  13.  * these visible applets.
  14.  *
  15.  * In this example, two visible applets are used along with the one
  16.  * Mediator class. The Developer and Client class generate text strings which
  17.  * represent conversation.  The Mediator object(s) take those text
  18.  * strings and distribute them to the other applet (Developer to Client and
  19.  * Client to Developer).
  20.  *
  21.  * The result is two distinct applet objects transmitting data back and
  22.  * forth. This sort of project can be very useful in developing more
  23.  * interesting Web pages as well as Web page applets which gather
  24.  * information about usage, etc.  The Mediator class concept can be
  25.  * built upon to meet the needs of more specific Java-based Web
  26.  * applications.
  27.  */
  28.  
  29. /**
  30.  * The main Mediator class
  31.  */
  32.  
  33. class Mediator
  34. {
  35.         //Random number indices
  36.         public static int theNumber;
  37.         public static int oldNumber;
  38.  
  39.         //The information is distributed via these static Strings
  40.         public static String developerTalk;
  41.         public static String clientTalk;
  42.  
  43.         /**
  44.          * Generate a random number
  45.          */
  46.  
  47.         public int genRandom()
  48.         {
  49.             int temp = (int)(Math.random() * 100);
  50.             return temp;
  51.         }
  52.  
  53.         /**
  54.          * Returns the statement of the developer
  55.          */
  56.  
  57.         public String getDeveloperTalk()
  58.         {
  59.             return developerTalk;
  60.         }
  61.  
  62.         /**
  63.          * Sets the statement of the developer
  64.          */
  65.  
  66.         public void setDeveloperTalk(String s)
  67.         {
  68.             developerTalk = s;
  69.         }
  70.  
  71.         /**
  72.          * Returns the statement of the client
  73.          */
  74.  
  75.         public String getClientTalk()
  76.         {
  77.             return clientTalk;
  78.         }
  79.  
  80.         /**
  81.          * Sets the statement of the client
  82.          */
  83.  
  84.         public void setClientTalk(String s)
  85.         {
  86.             clientTalk = s;
  87.         }
  88. }
  89.